/**
 * Copyright © 2009 Qasky. All rights reserved.
 *
 * 整个项目通用状态管理
 *
 * @author Wang Hongya
 * @version 0.0.0 2019/11/20
 *
 * History:
 * (author, date, desc)
 * (Wang Hongya, 20191120, 添加注释)
 */
import request from '../libs/request'

const common = {
    state: {
        formStyle: {
            labelCol: {span: 6},
            wrapperCol: {span: 17}
        },
        formStyleUnit: {
            labelCol: {span: 8},
            wrapperCol: {span: 15}
        },
        formItemLayoutTask: {
            wrapperCol: {span: 20, offset: 6}
        },
        formItemLayoutWithOutLabel: {
            wrapperCol: {span: 20, offset: 6}
        },
        formItemLayoutWithOutLabelT: {
            wrapperCol: {span: 20, offset: 8}
        },
        aidDeviceList: [],
        aidTreeList:[],
        aidSuperiorTreeList:[],
        deviceManufacturerNameList:[],
        modeSettingListPage:{},
        maxLength:0,
        timeoutTime:4000,
        isLoginOut:false,
    },
    mutations: {
        saveAidDeviceList ( state, obj ) {
            state.aidDeviceList = obj.data
        },
        saveMaxLenght ( state, obj ) {
            state.maxLength = obj
        },
        saveAidTree ( state, obj ) {
            state.aidTreeList = obj.data
        },
        saveAidSuperiorTree ( state, obj ) {
            state.aidSuperiorTreeList = obj.data
        },
        saveDeviceManufacturerName ( state, obj ) {
            state.deviceManufacturerNameList = obj.data
        },
        getModeSettingListPage( state, obj){
            state.modeSettingListPage = obj
        },
        setLoginOut(state, obj){
            state.isLoginOut = obj;
        },
    },
    actions: {
        getLoginOut ({commit}, arg) {
            commit('setLoginOut', arg)
        },
        /** aid所有的设备List **/
        getAidDeviceListAct ( context) {
            return request ({
                url: 'api/deviceModel/getDeviceModelInfosByModelType',
                method: 'get',
                params:{modelType:'0'}
            }).then (res => {
                context.commit ('saveAidDeviceList', res.data)
            })
        },
        /** 获取单个设备型号的轮询属性 **/
        getAidTreeAct ( context,prams) {
            return request ({
                url: 'api/sysAid/getAidTree',
                method: 'get',
                params:prams
            }).then (res => {
                context.commit ('saveAidTree', res.data)
                return res.data
            })
        },
        /** aid获取所有私有组的tree **/
        getAidSuperiorTreeAct ( context) {
            return request ({
                url: 'api/sysAid/getAidSuperiorTree',
                method: 'get',
            }).then (res => {
                context.commit ('saveAidSuperiorTree', res.data)
                return res.data
            })
        },
        /** 获取所有厂商名称 **/
        getDeviceManufacturerNameAct ( context) {
            return request ({
                url: 'api/deviceModel/getDeviceManufacturerName',
                method: 'get',
            }).then (res => {
                context.commit ('saveDeviceManufacturerName', res.data)
                return res.data
            })
        },
        setModeSettingListPage ({commit}, arg) {
            commit('getModeSettingListPage', arg)
        },
        setMaxLenght ({commit}, arg) {
            commit('saveMaxLenght', arg)
        },
    }
}

export default common
